package com.example.homelicaisystem.utils;

import lombok.Data;

@Data
public class Result<T> {
    private int code;
    private String msg;
    private T data;

    private static final int OK = 200;
    private static final String OK_MSG = "成功";

    private static final int ERR = 300;
    private static final String Err_MSG = "错误";

    public static final int NOT_ENOUGH_MONEY = 301;
    public static final int USED_CASH = 302;
    public static final int NOT_ENOUGH_INVESTMENT = 303;

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> ok(T data) {
        return new Result<>(OK, OK_MSG, data);
    }

    public static <T> Result<T> err(String errMessage, T data) {
        return new Result<>(ERR, errMessage, data);
    }

    public static <T> Result<T> err(int code, String errMessage, T data) {
        return new Result<>(code, errMessage, data);
    }
}
